package com.thread.test20180827.lock;


/**
 * @Description:
 * @author: conceit
 * @Date: 2018/8/27 0027 14:19
 */
public class UnLockTest implements Runnable{

    //定义票
    private int tickets=100;

    @Override
    public void run() {



        while (true){
            try {

                if(tickets>0){
                    //如果注释掉Thread.sleep(100)，则最先调用的线程会一直调用
                    try {
                        Thread.sleep(100);
                    }catch (InterruptedException e){

                    }
                    System.out.println(Thread.currentThread().getName()+"正在出售"+--tickets+"张票！");
                }
            }catch (Exception e){
                e.printStackTrace();
            }
        }



    }
}
